package com.example.service.serviceImp;

import com.alibaba.fastjson.JSONObject;
import com.example.dao.OldPhotoMapper;
import com.example.pojo.OldPhoto;
import com.example.service.OldPhotoService;
import com.example.util.PhotoUtil;
import com.example.util.Qiniu;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Date;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;


public class OldPhotoServiceImpl implements OldPhotoService {
    OldPhotoMapper oldPhotoMapper;

    @Override
    public Object uploadPath(MultipartFile file) throws IOException {
        //String name=file.getOriginalFilename();
        String path= PhotoUtil.download(file);
        String url= (String) Qiniu.upload(path);
        return url;
    }

    /**
     * 插入照片
     *
     * @param json
     */
    @Override
    public Object addPhoto(JSONObject json,String url) {
        LocalDate localDate = LocalDate.now();
        Date date = Date.valueOf(localDate);
        OldPhoto oldPhoto=JSONObject.parseObject(json.toJSONString(),OldPhoto.class);
        oldPhoto.setUptime(date);
        oldPhoto.setUrl(url);
        oldPhotoMapper.insert(oldPhoto);
        return  oldPhoto;
    }


    @Override
    public void deletePhoto(Map<String, Object> photo) {

    }





}
